package org.example.mall.Service.impl;

import org.example.mall.Mapper.ProductsConfigMapper;
import org.example.mall.Mapper.ProductsMapper;
import org.example.mall.Pojo.ProductInfo;
import org.example.mall.Pojo.Products;
import org.example.mall.Pojo.ProductsConfig;
import org.example.mall.Service.ProductsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

@Service
public class ProductsServiceimpl implements ProductsService {
    @Autowired
    private ProductsMapper pMapper;
    @Autowired
    private ProductsConfigMapper pCMapper;

    @Override
    public List<Products> getPPreviewInfoList() {
        return pMapper.getProductsList();
    }

    @Override
    public ProductInfo getPInfoById(String pId) {
        Products p = pMapper.findByPId(pId);
        List<String> itemTitleL = pCMapper.findItemTitleByPId(pId);
        List<List<ProductsConfig>> pCLL = new java.util.ArrayList<>(Collections.emptyList());
        for(String itemTitle : itemTitleL) {
            pCLL.add(pCMapper.findPConfigByPIdItemTitle(pId,itemTitle));
        }
        ProductInfo tmp = new ProductInfo(p, pCLL);
        return tmp;
    }
    @Override
    public Products getPPreviewInfoByPId(String pId) {
        return pMapper.findByPId(pId);
    }

}
